<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"          			
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      >
    <ui:composition template="TaskProLayout.xhtml">
        <ui:define name="content">
            <div class="Post">
            <h:form id="teamForm">
                <p:dataTable value="#{teamBean.teams}" var="team" selectionMode="single"
                             selection="#{teamBean.selectedTeam}"
                             rowKey="#{team.id}" paginator="true" paginatorAlwaysVisible="false" rows="30"
                             emptyMessage="No teams were found.">
                    <p:column headerText="Team name">
                        <h:outputText value="#{team.name}" />
                    </p:column>
                    <p:column headerText="Team group">
                        <h:outputText value="#{team.group.code}" />
                    </p:column><p:column headerText="Team subject">
                        <h:outputText value="#{team.group.subject.code}" />
                    </p:column>
                </p:dataTable>
                <p:commandButton value="Choose" action="#{teamBean.selectTeam()}" update=":studentsInTeam"/>  
            </h:form>
            </div>
            <div class="Post">
            <h:form id="studentsInTeam">  
                <p:dataTable  rendered="#{teamBean.studentsRendered}"
                              rowKey="#{student.login}"
                              var="student" value="#{teamBean.finalStudents}"  
                              paginator="true" paginatorAlwaysVisible="false" rows="30"
                              emptyMessage="No students were found by specifi criteria."
                              selection="#{teamBean.selectedStudentsToRemove}" selectionMode="multiple"
                              >  
                    <f:facet name="header">  
                        <h:outputText value="Selected studens in team" />  <br/>
                        <p:commandButton value="Add student to team" action="#{teamBean.loadStudentToAdd()}" 
                                         update=":studentsInTeam" oncomplete="addUserToTeamDialog.show()"/> 
                        <p:commandButton value="Remove team" action="#{teamBean.removeTeam()}" 
                                         update=":studentsInTeam,:teamForm,:assignmentToDeleteDialog,:assignmentSubmitModificatedDialog"/> 

                    </f:facet>  
                    <p:column headerText="Login">  
                        <h:outputText value="#{student.login}" />  
                    </p:column> 
                    <p:column headerText="Name">  
                        <h:outputText value="#{student.name}" />  
                    </p:column>  
                    <p:column headerText="Surname">  
                        <h:outputText value="#{student.surname}" />  
                    </p:column> 
                    <p:column headerText="Email">  
                        <h:outputText value="#{student.email}" />  
                    </p:column> 
                    <f:facet name="footer">
                        <p:commandButton value="Remove selected students" action="#{teamBean.removeStudentsFromTeam()}"
                                         update=":studentsInTeam,:teamForm,:assignmentToDeleteDialog,:assignmentSubmitModificatedDialog"/> 
                    </f:facet>
                </p:dataTable>  
            </h:form>
            </div>
                <p:dialog header="Users to add to team in group :#{teamBean.selectedTeam.group.code} in subject #{teamBean.selectedTeam.group.subject.code}" 
                          widgetVar="addUserToTeamDialog" resizable="false" 
                          width="900" height="600"  modal="true"
                          dynamic="true"  appendToBody="true">  
                    <h:form id="studentsAddTable">
                    <p:dataTable 
                        rowKey="#{studentToAdd.login}"
                        var="studentToAdd" value="#{teamBean.students}"  
                        paginator="true" paginatorAlwaysVisible="false" rows="30"
                        id="studentsAddTable" selectionMode="multiple" selection="#{teamBean.selectedStudents}"
                        emptyMessage="No students were found by specifi criteria.">  
                        <f:facet name="header">  
                            <h:outputText value="Student to add" />  <br/>
                        </f:facet>  
                        <p:column headerText="Login">  
                            <h:outputText value="#{studentToAdd.login}" />  
                        </p:column> 
                        <p:column headerText="Name">  
                            <h:outputText value="#{studentToAdd.name}" />  
                        </p:column>  
                        <p:column headerText="Surname">  
                            <h:outputText value="#{studentToAdd.surname}" />  
                        </p:column> 
                        <p:column headerText="Email">  
                            <h:outputText value="#{studentToAdd.email}" />  
                        </p:column> 
                    </p:dataTable> 

                    <p:commandButton value="Add" update=":studentsInTeam" action="#{teamBean.addStudentToTeam()}" 
                                     ajax="true" oncomplete="addUserToTeamDialog.hide()" ></p:commandButton>
                    <p:commandButton value="Close" 
                                     ajax="true" oncomplete="addUserToTeamDialog.hide();"></p:commandButton>
                    </h:form>
                </p:dialog>  
                <p:dialog header="Assignment to delete" 
                          widgetVar="assignmentDialog" resizable="false" 
                          width="900" height="600"  modal="true" closable="false"
                          dynamic="true"  binding="#{teamBean.dialogWithAssginments}" 
                          appendToBody="true">
                    <h:form id="assignmentToDeleteDialog">
                    <h:outputText value="These assignment has empty teams which were assigned. Please decide, if 
                                  you want to remove them or let them in system." />
                    <p:dataTable 
                        rowKey="#{assignment.id}"
                        var="assignment" value="#{teamBean.assignmentToRemove}"  
                        paginator="true" paginatorAlwaysVisible="false" rows="30"
                        id="assignmentToDelete" 
                        >  
                        <f:facet name="header">  
                            <h:outputText value="Assignemnt with empty target teams" />  <br/>
                        </f:facet>  
                        <p:column headerText="Label">  
                            <h:outputText value="#{assignment.template.name}" />  
                        </p:column> 
                        <p:column headerText="Description">  
                            <h:outputText value="#{assignment.template.description}" />  
                        </p:column>  
                        <p:column headerText="Date of assignment">  
                            <h:outputText value="#{assignment.dateOfAssignment}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column> 
                        <p:column headerText="Deadline">  
                            <h:outputText value="#{assignment.deadline}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column> 
                        <p:column headerText="Subject">  
                            <h:outputText value="#{assignment.subject.code}" />  
                        </p:column> 
                        <p:column headerText="Max score">  
                            <h:outputText value="#{assignment.maxScore}" />  
                        </p:column> 
                    </p:dataTable> 
                    <h:outputText value="Action" /><br/>
                    <p:commandButton value="Delete assignments" action="#{teamBean.removeAssignments()}" 
                                     ajax="true"  ></p:commandButton>
                    <p:commandButton value="Let them empty" 
                                     ajax="true" action="#{teamBean.closeDialog()}"></p:commandButton>
                    </h:form>
                </p:dialog>  
                <p:dialog header="Modificated assignment submit" 
                          widgetVar="assignmentSubmitDialog" resizable="false" 
                          width="900" height="600"  modal="true" closable="false"
                          dynamic="true"  binding="#{teamBean.dialogWithAssginmentsSubmit}">  
                    <h:form  id="assignmentSubmitModificatedDialog">
                    <h:outputText value="These assignment has been modify. The submitted student was changed." />
                    <p:dataTable 
                        rowKey="#{assignmentSubmit.id}"
                        var="assignmentSubmit" value="#{teamBean.updatedAssignmentSubmit}"  
                        paginator="true" paginatorAlwaysVisible="false" rows="30"
                        id="assignmentSubmitModificated" 
                        >  
                        <f:facet name="header">  
                            <h:outputText value="Assignemnt to delete" />  <br/>
                        </f:facet>  
                        <p:column headerText="Label">  
                            <h:outputText value="#{assignmentSubmit.assignment.template.name}" />  
                        </p:column> 
                        <p:column headerText="Description">  
                            <h:outputText value="#{assignmentSubmit.assignment.template.description}" />  
                        </p:column>  
                        <p:column headerText="Date of submit">  
                            <h:outputText value="#{assignmentSubmit.dateOfSubmit}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column> 
                        <p:column headerText="Deadline">  
                            <h:outputText value="#{assignmentSubmit.assignment.deadline}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column> 
                        <p:column headerText="Subject">  
                            <h:outputText value="#{assignmentSubmit.assignment.subject.code}" />  
                        </p:column> 
                        <p:column headerText="Max score">  
                            <h:outputText value="#{assignmentSubmit.assignment.maxScore}" />  
                        </p:column> 
                        <p:column headerText="Earned score">  
                            <h:outputText value="#{assignmentSubmit.grade}" />  
                        </p:column> 

                        <p:column headerText="Evaluation">  
                            <h:outputText value="#{assignmentSubmit.evaluation}" />  
                        </p:column> 

                        <p:column headerText="State">  
                            <h:outputText value="#{assignmentSubmit.stateOfTask}" />  
                        </p:column> 
                    </p:dataTable> 
                    <p:commandButton value="Close" 
                                     ajax="true" action="#{teamBean.closeDialog()}"></p:commandButton>
                    </h:form>
                </p:dialog>  
        </ui:define>
    </ui:composition>
</html>